(********************************************************************)
(*	file:		XCmdGlue.Inc										*)
(*	version:	.5alpha												*)
(*																	*)
(* Dan Winkler's Hypercard glue and Koscheka's support routines		*)
(* for the Appletalk/Hypercard interface.							*)
(* ----------------------------------------------------------------	*)
(* By:		Donald Koscheka											*)
(* Date:	2-Feb-88												*)
(* © Copyright 1987, Apple Computer, Inc.							*)
(* All Rights Reserved												*)
(*																	*)
(* ----------------------------------------------------------------	*)
(*						Modification History						*)
(* ----------------------------------------------------------------	*)
(*  Date	   	| By	|	 				Description				*)
(* ----------------------------------------------------------------	*)
(*  2-Feb-88	| DK	| File Created								*)
(*  2-Mar-88	| DK	| Added connect routine for adsp			*)
(* 17-Mar-88| DK	| ALPHA RELEASE									*)
(* ----------------------------------------------------------------	*)
(********************************************************************)


(********************************************************************)
(*  Assumes the XCMD has included this file and has named its 		*)
(*	argument "paramPtr".											*)
(********************************************************************)


PROCEDURE DoJsr(addr: ProcPtr); INLINE $205F,$4E90;


FUNCTION StringMatch(pattern: Str255; target: Ptr): Ptr;
BEGIN
  WITH paramPtr^ DO
    BEGIN
      inArgs[1] := ORD(@pattern);
      inArgs[2] := ORD(target);
      request := xreqStringMatch;
      DoJsr(entryPoint);
      StringMatch := Ptr(outArgs[1]);
    END;
END;


FUNCTION PasToZero(str: Str255): Handle;
BEGIN
  WITH paramPtr^ DO
    BEGIN
      inArgs[1] := ORD(@str);
      request := xreqPasToZero;
      DoJsr(entryPoint);
      PasToZero := Handle(outArgs[1]);
    END;
END;


PROCEDURE ZeroToPas(zeroStr: Ptr; VAR pasStr: Str255);
BEGIN
  WITH paramPtr^ DO
    BEGIN
      inArgs[1] := ORD(zeroStr);
      inArgs[2] := ORD(@pasStr);
      request := xreqZeroToPas;
      DoJsr(entryPoint);
    END;
END;


FUNCTION StrToLong(str: Str31): LongInt;
BEGIN
  WITH paramPtr^ DO
    BEGIN
      inArgs[1] := ORD(@str);
      request := xreqStrToLong;
      DoJsr(entryPoint);
      StrToLong := outArgs[1];
    END;
END;


FUNCTION StrToNum(str: Str31): LongInt;
BEGIN
  WITH paramPtr^ DO
    BEGIN
      inArgs[1] := ORD(@str);
      request := xreqStrToNum;
      DoJsr(entryPoint);
      StrToNum := outArgs[1];
    END;
END;


FUNCTION StrToBool(str: Str31): BOOLEAN;
BEGIN
  WITH paramPtr^ DO
    BEGIN
      inArgs[1] := ORD(@str);
      request := xreqStrToBool;
      DoJsr(entryPoint);
      StrToBool := BOOLEAN(outArgs[1]);
    END;
END;


FUNCTION StrToExt(str: Str31): Extended;
VAR x: Extended;
BEGIN
  WITH paramPtr^ DO
    BEGIN
      inArgs[1] := ORD(@str);
      inArgs[2] := ORD(@x);
      request := xreqStrToExt;
      DoJsr(entryPoint);
      StrToExt := x;
    END;
END;


FUNCTION LongToStr(posNum: LongInt): Str31;
VAR str: Str31;
BEGIN
  WITH paramPtr^ DO
    BEGIN
      inArgs[1] := posNum;
      inArgs[2] := ORD(@str);
      request := xreqLongToStr;
      DoJsr(entryPoint);
      LongToStr := str;
    END;
END;


FUNCTION NumToStr(num: LongInt): Str31;
VAR str: Str31;
BEGIN
  WITH paramPtr^ DO
    BEGIN
      inArgs[1] := num;
      inArgs[2] := ORD(@str);
      request := xreqNumToStr;
      DoJsr(entryPoint);
      NumToStr := str;
    END;
END;


FUNCTION NumToHex(num: LongInt; nDigits: INTEGER): Str31;
VAR str: Str31;
BEGIN
  WITH paramPtr^ DO
    BEGIN
      inArgs[1] := num;
      inArgs[2] := nDigits;
      inArgs[3] := ORD(@str);
      request := xreqNumToHex;
      DoJsr(entryPoint);
      NumToHex := str;
    END;
END;


FUNCTION ExtToStr(num: Extended): Str31;
VAR str: Str31;
BEGIN
  WITH paramPtr^ DO
    BEGIN
      inArgs[1] := ORD(@num);
      inArgs[2] := ORD(@str);
      request := xreqExtToStr;
      DoJsr(entryPoint);
      ExtToStr := str;
    END;
END;


FUNCTION BoolToStr(bool: BOOLEAN): Str31;
VAR str: Str31;
BEGIN
  WITH paramPtr^ DO
    BEGIN
      inArgs[1] := LongInt(bool);
      inArgs[2] := ORD(@str);
      request := xreqBoolToStr;
      DoJsr(entryPoint);
      BoolToStr := str;
    END;
END;


PROCEDURE SendCardMessage(msg: Str255);
BEGIN
  WITH paramPtr^ DO
    BEGIN
      inArgs[1] := ORD(@msg);
      request := xreqSendCardMessage;
      DoJsr(entryPoint);
    END;
END;


FUNCTION EvalExpr(expr: Str255): Handle;
BEGIN
  WITH paramPtr^ DO
    BEGIN
      inArgs[1] := ORD(@expr);
      request := xreqEvalExpr;
      DoJsr(entryPoint);
      EvalExpr := Handle(outArgs[1]);
    END;
END;


FUNCTION StringLength(strPtr: Ptr): LongInt;
BEGIN
  WITH paramPtr^ DO
    BEGIN
      inArgs[1] := ORD(strPtr);
      request := xreqStringLength;
      DoJsr(entryPoint);
      StringLength := outArgs[1];
    END;
END;


FUNCTION GetGlobal(globName: Str255): Handle;
BEGIN
  WITH paramPtr^ DO
    BEGIN
      inArgs[1] := ORD(@globName);
      request := xreqGetGlobal;
      DoJsr(entryPoint);
      GetGlobal := Handle(outArgs[1]);
    END;
END;


PROCEDURE SetGlobal(globName: Str255; globValue: Handle );
BEGIN
  WITH paramPtr^ DO
    BEGIN
      inArgs[1] := ORD(@globName);
      inArgs[2] := ORD(globValue);
      request := xreqSetGlobal;
      DoJsr(entryPoint);
    END;
END;


FUNCTION GetFieldByName(cardFieldFlag: BOOLEAN; fieldName: Str255): Handle;
BEGIN
  WITH paramPtr^ DO
    BEGIN
      inArgs[1] := ORD(cardFieldFlag);
      inArgs[2] := ORD(@fieldName);
      request := xreqGetFieldByName;
      DoJsr(entryPoint);
      GetFieldByName := Handle(outArgs[1]);
    END;
END;


FUNCTION GetFieldByNum(cardFieldFlag: BOOLEAN; fieldNum: INTEGER): Handle;
BEGIN
  WITH paramPtr^ DO
    BEGIN
      inArgs[1] := ORD(cardFieldFlag);
      inArgs[2] := fieldNum;
      request := xreqGetFieldByNum;
      DoJsr(entryPoint);
      GetFieldByNum := Handle(outArgs[1]);
    END;
END;


FUNCTION GetFieldByID(cardFieldFlag: BOOLEAN; fieldID: INTEGER): Handle;
BEGIN
  WITH paramPtr^ DO
    BEGIN
      inArgs[1] := ORD(cardFieldFlag);
      inArgs[2] := fieldID;
      request := xreqGetFieldByID;
      DoJsr(entryPoint);
      GetFieldByID := Handle(outArgs[1]);
    END;
END;


PROCEDURE SetFieldByName(cardFieldFlag: BOOLEAN; fieldName: Str255; fieldVal: Handle);
BEGIN
  WITH paramPtr^ DO
    BEGIN
      inArgs[1] := ORD(cardFieldFlag);
      inArgs[2] := ORD(@fieldName);
      inArgs[3] := ORD(fieldVal);
      request := xreqSetFieldByName;
      DoJsr(entryPoint);
    END;
END;


PROCEDURE SetFieldByNum(cardFieldFlag: BOOLEAN; fieldNum: INTEGER; fieldVal: Handle);
BEGIN
  WITH paramPtr^ DO
    BEGIN
      inArgs[1] := ORD(cardFieldFlag);
      inArgs[2] := fieldNum;
      inArgs[3] := ORD(fieldVal);
      request := xreqSetFieldByNum;
      DoJsr(entryPoint);
    END;
END;


PROCEDURE SetFieldByID(cardFieldFlag: BOOLEAN; fieldID: INTEGER; fieldVal: Handle);
BEGIN
  WITH paramPtr^ DO
    BEGIN
      inArgs[1] := ORD(cardFieldFlag);
      inArgs[2] := fieldID;
      inArgs[3] := ORD(fieldVal);
      request := xreqSetFieldByID;
      DoJsr(entryPoint);
    END;
END;


FUNCTION StringEqual(str1,str2: Str255): BOOLEAN;
BEGIN
  WITH paramPtr^ DO
    BEGIN
      inArgs[1] := ORD(@str1);
      inArgs[2] := ORD(@str2);
      request := xreqStringEqual;
      DoJsr(entryPoint);
      StringEqual := BOOLEAN(outArgs[1]);
    END;
END;


PROCEDURE ReturnToPas(zeroStr: Ptr; VAR pasStr: Str255);
BEGIN
  WITH paramPtr^ DO
    BEGIN
      inArgs[1] := ORD(zeroStr);
      inArgs[2] := ORD(@pasStr);
      request := xreqReturnToPas;
      DoJsr(entryPoint);
    END;
END;


PROCEDURE ScanToReturn(VAR scanPtr: Ptr);
BEGIN
  WITH paramPtr^ DO
    BEGIN
      inArgs[1] := ORD(@scanPtr);
      request := xreqScanToReturn;
      DoJsr(entryPoint);
    END;
END;


PROCEDURE ScanToZero(VAR scanPtr: Ptr);
BEGIN
  WITH paramPtr^ DO
    BEGIN
      inArgs[1] := ORD(@scanPtr);
      request := xreqScanToZero;
      DoJsr(entryPoint);
    END;
END;


PROCEDURE ZeroBytes(dstPtr: Ptr; longCount: LongInt);
BEGIN
  WITH paramPtr^ DO
    BEGIN
      inArgs[1] := ORD(dstPtr);
      inArgs[2] := longCount;
      request := xreqZeroBytes;
      DoJsr(entryPoint);
    END;
END;

